package com.yc.register.biz;

import com.yc.register.dao.RegisterDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class RegisterBiz {
    @Resource
    private RegisterDao registerDao;

    public int register(String account, String username, String password, String address, String phone, String email) throws BizException {
        if (account == null || account.isEmpty()){
            throw new BizException("请填写您的真实姓名!");
        }
        if (username == null || username.isEmpty()){
            throw new BizException("请填写用户名!");
        }
        if (email == null || email.isEmpty()){
            throw new BizException("请填写邮箱!");
        }
        if (phone == null || phone.isEmpty()){
            throw new BizException("请填写联系方式!");
        }
        if (address == null || address.isEmpty()){
            throw new BizException("请填写地址!");
        }
        if (password == null || password.isEmpty()){
            throw new BizException("请填写密码!");
        }

        int reg = registerDao.register(account,username, password, address, phone, email);

        return reg;
    }

    public Object editPerson(String username, String gender, String age, String address, String phone, String email,
                             String school, String education, String profession, String job, String pcode,String account,String password
                             ) throws BizException
    {
        if (account == null || account.isEmpty()){
            throw new BizException("请填写您的真实姓名!");
        }
        if (password == null || password.isEmpty()){
            throw new BizException("请填写密码!");
        }
        if (username == null || username.isEmpty()){
            throw new BizException("请填写用户名!");
        }
        if (email == null || email.isEmpty()){
            throw new BizException("请填写邮箱!");
        }
        if (phone == null || phone.isEmpty()){
            throw new BizException("请填写联系方式!");
        }
        if (address == null || address.isEmpty()){
            throw new BizException("请填写地址!");
        }


        Object edi = registerDao.editPerson(username, gender, age, address, phone,
                email, school, education, profession, job, pcode, account, password);
        return edi;
    }

    public Object editCount(String newpwd, String email,String oldpwd ) throws BizException {
        if (oldpwd == null || oldpwd.isEmpty()){
            throw new BizException("请填写您的密码!");
        }
        if (email == null || email.isEmpty()){
            throw new BizException("请填写邮箱!");
        }
        if (newpwd == null || newpwd.isEmpty()){
            throw new BizException("请填写新密码!");
        }
        Object ed = registerDao.editCount(newpwd, email, oldpwd);
        return ed;
    }
}
